home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-05-01 | 52.2 KB | 1,859 lines | [TEXT/CWIE] |
- /*
- File: CDEFTesterUtils.cp
-
- Contains: Code to demonstrate creating and using all types of controls.
-
- Version: Appearance 1.0 SDK
-
- Copyright: © 1997-1999 by Apple Computer, Inc., all rights reserved.
-
- File Ownership:
-
- DRI: Edward Voas
-
- Other Contact: 7 of 9, Borg Collective
-
- Technology: OS Technologies Group
-
- Writers:
-
- (jss) Jeff Shulman
- (MAA) Matt Ackeret
- (edv) Ed Voas
-
- Change History (most recent first):
-
- <1.9> 4/7/99 jss Fix CarbonLib compilation problems
- <14> 6/8/98 MAA Added title for triangle (not drawn in Allegro)
- <13> 2/18/98 MAA Add list control
- <12> 1/22/98 MAA Add support for auto-toggle variants for checkbox/radio button
- <11> 12/18/97 edv Fix compiler warnings.
- <10> 11/21/97 MAA Add UserPane
- <9> 11/7/97 MAA Remove tab count limitation
- <8> 11/6/97 MAA Make tab names variable length.
- <7> 11/5/97 MAA add Tabs
- <6> 10/31/97 MAA fix window title in CreateCheckBoxOrRadioButton
- <5> 10/31/97 MAA fix clock size in CreateClock
- <4> 10/28/97 MAA Remove temporary editText control bug checking code
- <3> 10/28/97 MAA Create many dialogs invisible then show after changes made
- <2> 10/28/97 edv Use RadioGroup control!
- <1> 9/11/97 edv First checked in.
- */
-
- #include "AppearanceSamplePrefix.h"
-
- #include <TextUtils.h>
- #include <Appearance.h>
- #include <Resources.h>
- #include <Controls.h>
- #include <ControlDefinitions.h>
- #include <Lists.h>
- #include <NumberFormatting.h>
- #include "CDEFTesterUtils.h"
- #include "BevelButtonItems.h"
- #include "RadioGroup.h"
- #include "AppearanceHelpers.h"
-
- enum
- {
- kLeftArrow = 0x1C,
- kRightArrow = 0x1D,
- kUpArrow = 0x1E,
- kDownArrow = 0x1F,
- kBackspace = 0x08
- };
-
- enum { kSmall = 1, kNormal, kLarge };
- enum { kMomentary = 1, kToggles, kSticky };
- enum { kTextOnly = 1, kIconSuite, kColorIcon, kPicture };
- enum { kPlaceNormal = 1, kPlaceLeft, kPlaceRight, kPlaceAbove, kPlaceBelow, kPlaceSys };
- enum { kTextSysDir = 1, kTextLeft, kTextRight, kTextCenter };
- enum { kGraphicSysDir = 1, kGraphicCenter, kGraphicLeft, kGraphicRight,
- kGraphicTop, kGraphicBottom, kGraphicTopLeft, kGraphicBotLeft,
- kGraphicTopRight, kGraphicBotRight };
-
- static void GetPictureSize( SInt16 resID, SInt32* height, SInt32* width );
- static void GetIconSize( SInt16 resID, SInt32* height, SInt32* width );
- static ControlHandle CreatePictureOrIconCDEF( WindowPtr window, Boolean isPicture );
- static ControlHandle CreateCheckBoxOrRadioButton( WindowPtr window, Boolean isCheckBox );
- static pascal void UserPaneDrawProc(ControlHandle theControl, SInt16 thePart);
-
- ControlHandle
- CreateBevelButton( WindowPtr window )
- {
- DialogPtr dialog;
- SInt16 itemHit = 0;
- ControlRef control = nil;
- SInt16 type;
- Handle handle;
- Rect rect;
- SInt32 stringNumber;
- ControlButtonContentInfo content;
- SInt16 menuID;
- ControlBevelThickness thickness;
- ControlBevelButtonBehavior behavior;
- ControlBevelButtonMenuBehavior menuBehavior;
- ControlBevelButtonMenuPlacement menuPlacement;
- Str255 text, title;
- Rect bounds = { 0, 0, 48, 48 };
-
- ControlButtonGraphicAlignment graphicAlign;
- ControlButtonTextPlacement placement;
- ControlButtonTextAlignment alignment;
- SInt32 longOffset;
- SInt16 offset;
- SInt32 temp;
- Point graphicOffset;
- ControlHandle tempControl;
-
- dialog = GetNewDialog( 2000, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- GetDialogItemAsControl( dialog, kBevelSizePopup, &tempControl );
- SetControlValue( tempControl, kSmall );
-
- GetDialogItemAsControl( dialog, kBevelBehaviorPopup, &tempControl );
- SetControlValue( tempControl, kMomentary );
-
- GetDialogItemAsControl( dialog, kBevelContentPopup, &tempControl );
- SetControlValue( tempControl, kTextOnly );
-
- GetDialogItemAsControl( dialog, kBevelTextPlacePopup, &tempControl );
- SetControlValue( tempControl, kPlaceNormal );
-
- GetDialogItemAsControl( dialog, kBevelTextAlignPopup, &tempControl );
- SetControlValue( tempControl, kTextCenter );
-
- GetDialogItemAsControl( dialog, kBevelGraphicAlignPopup, &tempControl );
- SetControlValue( tempControl, kGraphicCenter );
-
- SetDialogDefaultItem( dialog, kBevelOKButton );
- SetDialogCancelItem( dialog, kBevelCancelButton );
-
- ShowWindow( GetDialogWindow( dialog ) );
-
- while ( itemHit != kBevelCancelButton && itemHit != kBevelOKButton )
- {
- ModalDialog( nil, &itemHit );
-
- GetDialogItemAsControl( dialog, itemHit, &tempControl );
- switch ( itemHit )
- {
- case kBevelOffsetCheck:
- case kBevelMultiMenuCheck:
- case kBevelMenuOnRightCheck:
- {
- SInt16 value = GetControlValue( tempControl );
- SetControlValue( tempControl, !value );
- }
- break;
-
- }
- }
-
- if ( itemHit == kBevelCancelButton )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- // Get the content type
-
- GetDialogItemAsControl( dialog, kBevelContentPopup, &tempControl );
- switch ( GetControlValue( tempControl ) )
- {
- case kTextOnly: content.contentType = kControlContentTextOnly; break;
- case kIconSuite: content.contentType = kControlContentIconSuiteRes; break;
- case kColorIcon: content.contentType = kControlContentCIconRes; break;
- case kPicture: content.contentType = kControlContentPictRes; break;
- }
-
- // Now get the resource ID for the content, if we
- // have chosen something other than text only.
-
- if ( content.contentType != kControlContentTextOnly )
- {
- GetDialogItem( dialog, kBevelContentIDText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &stringNumber );
- content.u.resID = stringNumber;
- }
-
- // Get the menu
-
- GetDialogItem( dialog, kBevelMenuIDText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &stringNumber );
- menuID = stringNumber;
-
- // determine our bevel size
-
- GetDialogItemAsControl( dialog, kBevelSizePopup, &tempControl );
- switch( GetControlValue( tempControl ) )
- {
- case kSmall: thickness = kControlBevelButtonSmallBevel; break;
- default:
- case kNormal: thickness = kControlBevelButtonNormalBevel; break;
- case kLarge: thickness = kControlBevelButtonLargeBevel; break;
- }
-
- // determine our behavior
-
- GetDialogItemAsControl( dialog, kBevelBehaviorPopup, &tempControl );
- switch( GetControlValue( (ControlHandle)handle ) )
- {
- default:
- case kMomentary: behavior = kControlBehaviorPushbutton; break;
- case kToggles: behavior = kControlBehaviorToggles; break;
- case kSticky: behavior = kControlBehaviorSticky; break;
- }
-
- // See if we should offset the contents and or this into our behavior.
-
- GetDialogItemAsControl( dialog, kBevelOffsetCheck, &tempControl );
- if ( GetControlValue( tempControl ) == 1 )
- behavior |= kControlBehaviorOffsetContents;
-
- // See what our menu's behavior is.
-
- menuBehavior = kControlBehaviorSingleValueMenu;
- GetDialogItemAsControl( dialog, kBevelMultiMenuCheck, &tempControl );
- if ( GetControlValue( tempControl ) == 1 )
- menuBehavior |= kControlBehaviorMultiValueMenu;
-
- // See if the menu shoule be on the right and stuff this into
- // our menu placement.
-
- GetDialogItemAsControl( dialog, kBevelMenuOnRightCheck, &tempControl );
- if ( GetControlValue( tempControl ) == 1 )
- menuPlacement = kControlBevelButtonMenuOnRight;
- else
- menuPlacement = kControlBevelButtonMenuOnBottom;
-
- // Calculate the size of our button
-
- GetDialogItem( dialog, kBevelHeightText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &temp );
- bounds.bottom = temp;
- GetDialogItem( dialog, kBevelWidthText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &temp );
- bounds.right = temp;
-
- // Get the text alignment, offset, and placement
-
- GetDialogItemAsControl( dialog, kBevelTextAlignPopup, &tempControl );
- switch ( GetControlValue( tempControl ) )
- {
- case kTextSysDir: alignment = kControlBevelButtonAlignTextSysDirection; break;
- case kTextLeft: alignment = kControlBevelButtonAlignTextFlushLeft; break;
- case kTextRight: alignment = kControlBevelButtonAlignTextFlushRight; break;
- case kTextCenter: alignment = kControlBevelButtonAlignTextCenter; break;
- }
-
- GetDialogItem( dialog, kBevelTextOffsetText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &longOffset );
- offset = longOffset;
-
- GetDialogItemAsControl( dialog, kBevelTextPlacePopup, &tempControl );
- switch ( GetControlValue( tempControl ) )
- {
- case kPlaceNormal: placement = kControlBevelButtonPlaceNormally; break;
- case kPlaceLeft: placement = kControlBevelButtonPlaceToLeftOfGraphic; break;
- case kPlaceRight: placement = kControlBevelButtonPlaceToRightOfGraphic; break;
- case kPlaceAbove: placement = kControlBevelButtonPlaceAboveGraphic; break;
- case kPlaceBelow: placement = kControlBevelButtonPlaceBelowGraphic; break;
- case kPlaceSys: placement = kControlBevelButtonPlaceSysDirection; break;
- }
-
- // Get the graphic alignment and offsets
-
- GetDialogItemAsControl( dialog, kBevelGraphicAlignPopup, &tempControl );
- switch ( GetControlValue( tempControl ) )
- {
- case kGraphicSysDir: graphicAlign = kControlBevelButtonAlignSysDirection; break;
- case kGraphicCenter: graphicAlign = kControlBevelButtonAlignCenter; break;
- case kGraphicLeft: graphicAlign = kControlBevelButtonAlignLeft; break;
- case kGraphicRight: graphicAlign = kControlBevelButtonAlignRight; break;
- case kGraphicTop: graphicAlign = kControlBevelButtonAlignTop; break;
- case kGraphicBottom: graphicAlign = kControlBevelButtonAlignBottom; break;
- case kGraphicTopLeft: graphicAlign = kControlBevelButtonAlignTopLeft; break;
- case kGraphicBotLeft: graphicAlign = kControlBevelButtonAlignBottomLeft; break;
- case kGraphicTopRight: graphicAlign = kControlBevelButtonAlignTopRight; break;
- case kGraphicBotRight: graphicAlign = kControlBevelButtonAlignBottomRight; break;
- }
-
- GetDialogItem( dialog, kBevelGraphicHOffsetText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &longOffset );
- graphicOffset.h = longOffset;
- GetDialogItem( dialog, kBevelGraphicVOffsetText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &longOffset );
- graphicOffset.v = longOffset;
-
- // Get the title.
-
- GetDialogItem( dialog, kBevelTitleText, &type, &handle, &rect );
- GetDialogItemText( handle, title );
-
- DisposeDialog( dialog );
-
- CreateBevelButtonControl( window, &bounds, title, thickness, behavior, &content,
- menuID, menuBehavior, menuPlacement, &control );
- if ( control == nil ) return nil;
-
- SetControlVisibility( control, false, false );
-
- SetControlData( control, 0, kControlBevelButtonTextPlaceTag, sizeof( ControlButtonTextPlacement ),
- (Ptr)&placement );
-
- SetControlData( control, 0, kControlBevelButtonTextAlignTag, sizeof( ControlButtonTextAlignment ),
- (Ptr)&alignment );
-
- SetControlData( control, 0, kControlBevelButtonGraphicAlignTag, sizeof( ControlButtonGraphicAlignment ),
- (Ptr)&graphicAlign );
-
- SetControlData( control, 0, kControlBevelButtonTextOffsetTag, sizeof( SInt16 ), (Ptr)&offset );
- SetControlData( control, 0, kControlBevelButtonGraphicOffsetTag, sizeof( Point ), (Ptr)&graphicOffset );
-
- return control;
- }
-
-
- static pascal void
- UserPaneDrawProc (ControlHandle theControl, SInt16 thePart)
- {
- #pragma unused( thePart )
- Rect bounds;
-
- GetControlBounds( theControl, &bounds );
-
- FrameRect( &bounds );
- }
-
-
- /***
- This is just a very simplistic User Pane that that draws a rectangle around its frame, and
- returns an incrementing number for the part codes. It shows how to set up a few of the
- various procedures needed for User Panes.
- ***/
- ControlHandle
- CreateUserPane( WindowPtr window )
- {
- Rect bounds = { 0, 0, 100, 100 };
- ControlHandle theControl;
-
- CreateUserPaneControl( window, &bounds, 0, &theControl );
- if (theControl)
- {
- ControlUserPaneDrawUPP myPaneDrawProc;
-
- SetControlVisibility( theControl, false, false );
- myPaneDrawProc = NewControlUserPaneDrawProc(UserPaneDrawProc);
- SetControlData(theControl, 0, kControlUserPaneDrawProcTag, sizeof(ControlUserPaneDrawUPP), (Ptr) &myPaneDrawProc);
-
- return(theControl);
- }
-
- return(nil);
- }
-
-
- ControlHandle
- CreateChasingArrows( WindowPtr window )
- {
- Rect bounds = { 0, 0, 16, 16 };
- ControlRef control;
-
- CreateChasingArrowsControl( window, &bounds, &control );
-
- if ( control != nil )
- SetControlVisibility( control, false, false );
-
- return control;
- }
-
- ControlHandle
- CreateDivider( WindowPtr window )
- {
- DialogPtr dialog;
- SInt16 itemHit = 0;
- ControlHandle control = nil;
- SInt16 type;
- Handle handle;
- Rect rect;
- SInt32 length;
- Str255 text;
- Rect bounds = { 0, 0, 4, 4 };
- ControlHandle tempControl;
-
- dialog = GetNewDialog( 2001, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- SetDialogDefaultItem( dialog, kDividerOKButton );
- SetDialogCancelItem( dialog, kDividerCancelButton );
-
- while ( itemHit != kDividerCancelButton && itemHit != kDividerOKButton )
- {
- ModalDialog( nil, &itemHit );
- }
-
- if ( itemHit == kDividerCancelButton )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- GetDialogItem( dialog, kLengthText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &length );
-
- GetDialogItemAsControl( dialog, kDividerRadioGroup, &tempControl );
- if ( GetControlValue( tempControl ) == 1 )
- bounds.right = bounds.left + length;
- else
- bounds.bottom = bounds.top + length;
-
- DisposeDialog( dialog );
-
- CreateSeparatorControl( window, &bounds, &control );
- if ( control != nil )
- SetControlVisibility( control, false, false );
-
- return control;
- }
-
- ControlHandle
- CreateTriangle( WindowPtr window )
- {
- DialogPtr dialog;
- SInt16 itemHit = 0;
- ControlHandle control = nil;
- Rect bounds = { 0, 0, 12, 12 };
- ControlDisclosureTriangleOrientation orientation;
- Boolean autoToggles;
- ControlHandle tempControl;
-
- dialog = GetNewDialog( 2002, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- SetDialogDefaultItem( dialog, kTriangleOKButton );
- SetDialogCancelItem( dialog, kTriangleCancelButton );
-
- while ( itemHit != kTriangleCancelButton && itemHit != kTriangleOKButton )
- {
- ModalDialog( nil, &itemHit );
-
- GetDialogItemAsControl( dialog, itemHit, &tempControl );
- switch ( itemHit )
- {
- case kLeftFacingCheck:
- case kAutoTrackCheck:
- SetControlValue( tempControl, !GetControlValue( tempControl ) );
- break;
- }
- }
-
- if ( itemHit == kTriangleCancelButton )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- GetDialogItemAsControl( dialog, kLeftFacingCheck, &tempControl );
- if ( GetControlValue( tempControl ) == 1 )
- orientation = kControlDisclosureTrianglePointLeft;
- else
- orientation = kControlDisclosureTrianglePointRight;
-
- GetDialogItemAsControl( dialog, kAutoTrackCheck, &tempControl );
- if ( GetControlValue( tempControl ) == 1 )
- autoToggles = true;
- else
- autoToggles = false;
-
- DisposeDialog( dialog );
-
- CreateDisclosureTriangleControl( window, &bounds, orientation, "\pTriangle",
- false, autoToggles, &control );
- if ( control != nil )
- SetControlVisibility( control, false, false );
-
- return control;
- }
-
- ControlHandle
- CreateEditText( WindowPtr window )
- {
- DialogPtr dialog;
- SInt16 itemHit = 0;
- ControlHandle control = nil;
- Rect bounds = { 20, 20, 36, 200 };
- Boolean isPassword;
- ControlHandle tempControl;
- unsigned char *string = "\pSample Text";
-
- dialog = GetNewDialog( 2014, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- SetDialogDefaultItem( dialog, kETOKButton );
- SetDialogCancelItem( dialog, kETCancelButton );
-
- while ( itemHit != kETCancelButton && itemHit != kETOKButton )
- {
- ModalDialog( nil, &itemHit );
-
- GetDialogItemAsControl( dialog, itemHit, &tempControl );
- if (itemHit == kETPasswordCheck)
- SetControlValue(tempControl, !GetControlValue(tempControl));
- }
-
- if ( itemHit == kETCancelButton )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- GetDialogItemAsControl( dialog, kETPasswordCheck, &tempControl );
- if (GetControlValue( tempControl ))
- isPassword = true;
- else
- isPassword = false;
-
- DisposeDialog( dialog );
-
- CreateEditTextControl( window, &bounds, "\p", isPassword, false, nil, &control );
- if (!control) return nil;
-
- SetControlVisibility( control, false, false );
-
- SetKeyboardFocus(window, control, kControlFocusNextPart);
-
- if (! isPassword)
- SetControlData(control,kControlNoPart,kControlEditTextTextTag,*string,(Ptr) string + 1);
-
- return control;
- }
-
- ControlHandle
- CreateSlider( WindowPtr window )
- {
- DialogPtr dialog;
- SInt16 itemHit = 0;
- ControlHandle dialogControl,tempControl;
- ControlSliderOrientation orientation;
- UInt16 numTickMarks;
- ControlRef control;
- Rect bounds = { 20, 20, 80, 200 };
- Boolean enableItems,alreadyEnabled;
-
- dialog = GetNewDialog( 2016, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- SetDialogDefaultItem( dialog, kStdOkItemIndex );
- SetDialogCancelItem( dialog, kStdCancelItemIndex );
- GetDialogItemAsControl(dialog, kSliderDirectional, &tempControl);
- SetControlValue(tempControl, 1);
- ShowWindow( GetDialogWindow( dialog ) );
-
- while ( itemHit != kStdOkItemIndex && itemHit != kStdCancelItemIndex )
- {
- ModalDialog( nil, &itemHit );
-
- GetDialogItemAsControl(dialog, itemHit, &dialogControl);
-
- if ((itemHit == kSliderTickMarks) || (itemHit == kSliderReverse))
- SetControlValue(dialogControl, !GetControlValue(dialogControl)); // toggle checkbox
-
- if ((itemHit == kSliderNonDirectional) || (itemHit == kSliderDirectional))
- {
- alreadyEnabled = GetControlValue(dialogControl);
-
- SetControlValue(dialogControl, 1);
- GetDialogItemAsControl(dialog, (itemHit == kSliderNonDirectional) ? kSliderDirectional : kSliderNonDirectional, &tempControl);
- SetControlValue(tempControl, 0);
-
- enableItems = (itemHit == kSliderDirectional);
-
- if (!alreadyEnabled) // don't enable/disable sub-items every time, it flickers
- {
- GetDialogItemAsControl(dialog, kSliderTickMarks, &tempControl);
- HiliteControl(tempControl, enableItems ? 0 : kControlDisabledPart);
- GetDialogItemAsControl(dialog, kSliderReverse, &tempControl);
- HiliteControl(tempControl, enableItems ? 0 : kControlDisabledPart);
- }
- }
- }
-
- if ( itemHit == kStdCancelItemIndex )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- GetDialogItemAsControl(dialog, kSliderNonDirectional, &tempControl);
-
- if (GetControlValue(tempControl))
- {
- orientation = kControlSliderDoesNotPoint;
- numTickMarks = 0;
- }
- else
- {
- GetDialogItemAsControl(dialog, kSliderTickMarks, &tempControl);
-
- if (GetControlValue(tempControl))
- numTickMarks = 5;
- else
- numTickMarks = 0;
-
- GetDialogItemAsControl(dialog, kSliderReverse, &tempControl);
-
- if (GetControlValue(tempControl))
- orientation = kControlSliderPointsUpOrLeft;
- else
- orientation = kControlSliderPointsDownOrRight;
- }
-
- DisposeDialog( dialog );
-
- CreateSliderControl( window, &bounds, 0, 0, 100, orientation, numTickMarks, false, nil, &control );
- if ( control != nil )
- SetControlVisibility( control, false, false );
-
- return control;
- }
-
- ControlHandle
- CreateClock( WindowPtr window )
- {
- DialogPtr dialog;
- SInt16 itemHit = 0;
- ControlHandle control = nil,dialogControl,tempControl;
- Rect bounds = { 0, 0, 23, 125 };
- ControlClockType clockTypes[4] = {kControlClockTypeHourMinute, kControlClockTypeHourMinuteSecond, kControlClockTypeMonthDay, kControlClockTypeMonthDayYear};
- short itemIndex,kindIndex=0;
-
- dialog = GetNewDialog( 2017, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- SetDialogDefaultItem( dialog, kStdOkItemIndex );
- SetDialogCancelItem( dialog, kStdCancelItemIndex );
- GetDialogItemAsControl(dialog, kClockTime, &tempControl);
- SetControlValue(tempControl, 1);
- ShowWindow( GetDialogWindow( dialog ) );
-
- while ((itemHit != kStdOkItemIndex) && (itemHit != kStdCancelItemIndex))
- {
- ModalDialog( nil, &itemHit );
-
- GetDialogItemAsControl(dialog, itemHit, &dialogControl);
-
- if ((itemHit >= kClockTime) && (itemHit <= kClockMonthYear) && !GetControlValue(dialogControl))
- // if it's radio buttons and the radio button isn't already selected
- {
- for(itemIndex=kClockTime;itemIndex<=kClockMonthYear;itemIndex++)
- {
- GetDialogItemAsControl(dialog, itemIndex, &tempControl);
-
- if (itemIndex == itemHit)
- SetControlValue(tempControl, 1);
- else
- SetControlValue(tempControl, 0);
- }
- }
-
- }
-
- if ( itemHit == kStdCancelItemIndex )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- for(itemIndex=kClockTime;itemIndex<=kClockMonthYear;itemIndex++)
- {
- GetDialogItemAsControl(dialog, itemIndex, &tempControl);
-
- if (GetControlValue(tempControl))
- kindIndex = itemIndex - kClockTime;
- }
-
- DisposeDialog( dialog );
-
- CreateClockControl( window, &bounds, clockTypes[kindIndex], kControlClockNoFlags, &control );
-
- if ( control == nil )
- return nil;
-
- SetControlVisibility( control, false, false );
-
- SetKeyboardFocus(window, control, kControlFocusNextPart);
-
- return(control);
- }
-
- ControlHandle
- CreateStaticText( WindowPtr window )
- {
- DialogPtr dialog;
- SInt16 itemHit = 0;
- ControlHandle control = nil;
- Rect bounds = { 20, 20, 52, 200 };
- DialogItemType dummyType;
- Handle textItem;
- Rect dummyRect;
- Str255 text;
-
- dialog = GetNewDialog( 2015, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- SetDialogDefaultItem( dialog, kSTOKButton );
- SetDialogCancelItem( dialog, kSTCancelButton );
-
- while ( itemHit != kSTCancelButton && itemHit != kSTOKButton )
- ModalDialog( nil, &itemHit );
-
-
- if ( itemHit == kSTCancelButton )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- GetDialogItem(dialog, 3, &dummyType, &textItem, &dummyRect);
-
- GetDialogItemText(textItem, text);
-
- DisposeDialog( dialog );
-
- CreateStaticTextControl( window, &bounds, "\p", nil, &control );
-
- if (!control)
- return(nil);
-
- SetControlVisibility( control, false, false );
-
- SetControlData(control, kControlNoPart, kControlStaticTextTextTag, *text, (Ptr) &(text[1]));
-
- return(control);
- }
-
-
-
- ControlHandle
- CreateFinderHeader( WindowPtr window )
- {
- DialogPtr dialog;
- SInt16 itemHit = 0;
- ControlHandle control = nil;
- SInt16 type;
- Handle handle;
- Rect rect;
- Rect bounds = { 0, 0, 0, 0 };
- Boolean isListHeader;
- Str255 text;
- SInt32 number;
- ControlHandle tempControl;
-
- dialog = GetNewDialog( 2003, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- SetDialogDefaultItem( dialog, kFHOKButton );
- SetDialogCancelItem( dialog, kFHCancelButton );
-
- while ( itemHit != kFHCancelButton && itemHit != kFHOKButton )
- {
- ModalDialog( nil, &itemHit );
-
- GetDialogItemAsControl( dialog, itemHit, &tempControl );
- switch ( itemHit )
- {
- case kFHListViewCheck:
- SetControlValue( tempControl, !GetControlValue( tempControl ) );
- break;
- }
- }
-
- if ( itemHit == kFHCancelButton )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- isListHeader = false;
- GetDialogItemAsControl( dialog, kFHListViewCheck, &tempControl );
- if ( GetControlValue( tempControl ) == 1 )
- isListHeader = true;;
-
- GetDialogItem( dialog, kFHHeightText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &number );
- bounds.bottom = number;
-
- GetDialogItem( dialog, kFHWidthText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &number );
- bounds.right = number;
-
- DisposeDialog( dialog );
-
- CreateWindowHeaderControl( window, &bounds, isListHeader, &control );
- if ( control == nil ) return nil;
-
- SetControlVisibility( control, false, false );
-
- return control;
- }
-
- ControlHandle
- CreateIconCDEF( WindowPtr window )
- {
- return CreatePictureOrIconCDEF( window, false );
- }
-
- ControlHandle
- CreatePictureCDEF( WindowPtr window )
- {
- return CreatePictureOrIconCDEF( window, true );
- }
-
- static ControlHandle
- CreatePictureOrIconCDEF( WindowPtr window, Boolean isPicture )
- {
- DialogPtr dialog;
- SInt16 itemNo;
- SInt16 type;
- Handle handle;
- Rect rect;
- Str255 text;
- SInt32 resID, height, width;
- Boolean dontTrack = false;
- Rect bounds = { 0, 0, 0, 0 };
- ControlKeyFilterUPP filterProc;
- ControlRef tempControl;
- ControlRef control;
-
- dialog = GetNewDialog( 2005, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- if ( ! isPicture )
- SetWTitle( GetDialogWindow( dialog ), "\pIcon CDEF" );
- else
- SetWTitle( GetDialogWindow( dialog ), "\pPicture CDEF" );
-
- SetDialogDefaultItem( dialog, kIconOK );
- SetDialogCancelItem( dialog, kIconCancel );
-
- filterProc = NewControlKeyFilterProc( NumericFilter );
- GetDialogItemAsControl( dialog, kIconResIDText, &tempControl );
- SetEditTextKeyFilter( tempControl, filterProc );
- GetDialogItemAsControl( dialog, kIconHeightText, &tempControl );
- SetEditTextKeyFilter( tempControl, filterProc );
- GetDialogItemAsControl( dialog, kIconWidthText, &tempControl );
- SetEditTextKeyFilter( tempControl, filterProc );
-
- ShowWindow( GetDialogWindow( dialog ) );
-
- while( itemNo != kIconCancel && itemNo != kIconOK )
- {
- ModalDialog( nil, &itemNo );
-
- GetDialogItemAsControl( dialog, itemNo, &tempControl );
- switch ( itemNo )
- {
- case kIconNoHitCheck:
- SetControlValue( tempControl, !GetControlValue( tempControl ) );
- break;
-
- case kIconUseRectCheck:
- SetControlValue( tempControl, !GetControlValue( tempControl ) );
- if ( GetControlValue( tempControl ) == 1 )
- {
- GetDialogItemAsControl( dialog, kIconHeightLabelText, &tempControl );
- DeactivateControl( tempControl );
- GetDialogItemAsControl( dialog, kIconWidthLabelText, &tempControl );
- DeactivateControl( tempControl );
- GetDialogItemAsControl( dialog, kIconHeightText, &tempControl );
- DeactivateControl( tempControl );
- GetDialogItemAsControl( dialog, kIconWidthText, &tempControl );
- DeactivateControl( tempControl );
- }
- else
- {
- GetDialogItemAsControl( dialog, kIconHeightLabelText, &tempControl );
- ActivateControl( tempControl );
- GetDialogItemAsControl( dialog, kIconWidthLabelText, &tempControl );
- ActivateControl( tempControl );
- GetDialogItemAsControl( dialog, kIconHeightText, &tempControl );
- ActivateControl( tempControl );
- GetDialogItemAsControl( dialog, kIconWidthText, &tempControl );
- ActivateControl( tempControl );
- }
- break;
- }
- }
- DisposeControlKeyFilterUPP( filterProc );
-
- if ( itemNo == kIconCancel )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- GetDialogItem( dialog, kIconResIDText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &resID );
-
- GetDialogItemAsControl( dialog, kIconUseRectCheck, &tempControl );
- if ( GetControlValue( tempControl ) == 1 )
- {
- if ( isPicture )
- GetPictureSize( resID, &height, &width );
- else
- GetIconSize( resID, &height, &width );
- }
- else
- {
- GetDialogItem( dialog, kIconHeightText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &height );
-
- GetDialogItem( dialog, kIconWidthText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &width );
- }
- GetDialogItemAsControl( dialog, kIconNoHitCheck, &tempControl );
- if ( GetControlValue( tempControl ) == 1 )
- dontTrack = true;
-
- DisposeDialog( dialog );
-
- bounds.bottom = bounds.top + height;
- bounds.right = bounds.left + width;
-
- if ( isPicture )
- {
- ControlButtonContentInfo content;
-
- content.contentType = kControlNoContent;
- if ( resID != 0 )
- {
- content.contentType = kControlContentPictRes;
- content.u.resID = resID;
- }
-
- CreatePictureControl( window, &bounds, &content, dontTrack, &control );
- }
- else
- {
- ControlButtonContentInfo content;
-
- content.contentType = kControlNoContent;
- if ( resID != 0 )
- {
- content.contentType = kControlContentICONRes;
- content.u.resID = resID;
- }
-
- CreateIconControl( window, &bounds, &content, dontTrack, &control );
- }
-
- if ( control != nil )
- SetControlVisibility( control, false, false );
-
- return control;
- }
-
- ControlHandle
- CreateProgressBar( WindowPtr window )
- {
- DialogPtr dialog;
- SInt16 itemHit = 0;
- ControlHandle control = nil;
- SInt16 type;
- Handle handle;
- Rect rect;
- Rect bounds = { 0, 0, 16, 0 };
- Str255 text;
- SInt32 number;
- Boolean indeterminate;
- ControlHandle tempControl;
-
- dialog = GetNewDialog( 2006, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- SetDialogDefaultItem( dialog, kProgOKButton );
- SetDialogCancelItem( dialog, kProgCancelButton );
-
- while ( itemHit != kProgCancelButton && itemHit != kProgOKButton )
- {
- ModalDialog( nil, &itemHit );
-
- GetDialogItemAsControl( dialog, itemHit, &tempControl );
- switch ( itemHit )
- {
- case kProgIndeterminateCheck:
- SetControlValue( tempControl, !GetControlValue( tempControl ) );
- break;
- }
- }
-
- if ( itemHit == kProgCancelButton )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- GetDialogItemAsControl( dialog, kProgIndeterminateCheck, &tempControl );
- indeterminate = ( GetControlValue( tempControl ) == 1 );
-
- GetDialogItem( dialog, kProgLengthText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &number );
- bounds.right = number;
-
- DisposeDialog( dialog );
-
- CreateProgressBarControl( window, &bounds, 50, 0, 100, indeterminate, &control );
- if ( control == nil ) return nil;
-
- SetControlVisibility( control, false, false );
-
- return control;
- }
-
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Ä CreateLittleArrows PUBLIC
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Creates the little arrows CDEF. We just use a standard size - no options.
- //
- ControlHandle
- CreateLittleArrows( WindowPtr window )
- {
- Rect bounds = { 0, 0, 24, 13 };
- ControlRef control;
-
- CreateLittleArrowsControl( window, &bounds, 0, 0, 100, 1, &control );
-
- if ( control != nil )
- SetControlVisibility( control, false, false );
-
- return control;
- }
-
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Ä CreateGroupBox PUBLIC
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Creates a group box.
- //
- ControlHandle
- CreateGroupBox( WindowPtr window )
- {
- enum { kPrimary, kSecondary };
- enum { kText = 1, kCheckBox, kPopup };
-
- DialogPtr dialog;
- SInt16 itemHit = 0;
- SInt16 type;
- Handle handle;
- Rect rect;
- Rect bounds = { 0, 0, 16, 0 };
- ControlKeyFilterUPP filterProc;
- Str255 text, title;
- SInt32 height, width;
- ControlRef tempControl;
- Boolean isPrimary;
- SInt32 menuID;
- ControlRef control = nil;
-
- dialog = GetNewDialog( 2007, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- filterProc = NewControlKeyFilterProc( NumericFilter );
-
- GetDialogItemAsControl( dialog, kGroupMenuIDLabelText, &tempControl );
- DeactivateControl( tempControl );
- GetDialogItemAsControl( dialog, kGroupMenuIDText, &tempControl );
- DeactivateControl( tempControl );
-
- GetDialogItemAsControl( dialog, kGroupMenuIDText, &tempControl );
- SetEditTextKeyFilter( tempControl, filterProc );
- GetDialogItemAsControl( dialog, kGroupHeightText, &tempControl );
- SetEditTextKeyFilter( tempControl, filterProc );
- GetDialogItemAsControl( dialog, kGroupWidthText, &tempControl );
- SetEditTextKeyFilter( tempControl, filterProc );
-
- SetDialogDefaultItem( dialog, kGroupOKButton );
- SetDialogCancelItem( dialog, kGroupCancelButton );
-
- while ( itemHit != kGroupCancelButton && itemHit != kGroupOKButton )
- {
- ModalDialog( nil, &itemHit );
-
- GetDialogItemAsControl( dialog, itemHit, &tempControl );
- switch ( itemHit )
- {
- case kGroupVariantPopup:
- if ( GetControlValue( tempControl ) == kPopup )
- {
- GetDialogItemAsControl( dialog, kGroupMenuIDLabelText, &tempControl );
- ActivateControl( tempControl );
- GetDialogItemAsControl( dialog, kGroupMenuIDText, &tempControl );
- ActivateControl( tempControl );
- }
- else
- {
- GetDialogItemAsControl( dialog, kGroupMenuIDLabelText, &tempControl );
- DeactivateControl( tempControl );
- GetDialogItemAsControl( dialog, kGroupMenuIDText, &tempControl );
- DeactivateControl( tempControl );
- }
- }
- }
- DisposeControlKeyFilterUPP( filterProc );
-
- if ( itemHit == kGroupCancelButton )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- // Are we primary or secondary?
-
- isPrimary = true;
- GetDialogItemAsControl( dialog, kGroupRadioGroup, &tempControl );
- if ( GetControlValue( tempControl ) == 2 )
- isPrimary = false;
-
- // Calculate the bounding rectangle based on width/height
-
- GetDialogItem( dialog, kGroupHeightText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &height );
- GetDialogItem( dialog, kGroupWidthText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &width );
-
- bounds.bottom = height;
- bounds.right = width;
-
- // Get the title of the control
-
- GetDialogItem( dialog, kGroupTitleText, &type, &handle, &rect );
- GetDialogItemText( handle, title );
-
- GetDialogItemAsControl( dialog, kGroupVariantPopup, &tempControl );
- switch ( GetControlValue( tempControl ) )
- {
- case kCheckBox:
- CreateCheckGroupBoxControl( window, &bounds, title, isPrimary, false, &control );
- break;
-
- case kPopup:
- // get the menu
- GetDialogItem( dialog, kGroupMenuIDText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &menuID );
-
- CreatePopupGroupBoxControl( window, &bounds, title, isPrimary, menuID,
- true, 0, 0, 0, &control );
- break;
-
- case kText:
- CreateGroupBoxControl( window, &bounds, title, isPrimary, &control );
- break;
- }
- DisposeDialog( dialog );
-
- if ( control != nil )
- SetControlVisibility( control, false, false );
-
- return control;
- }
-
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Ä CreatePlacard PUBLIC
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // This routine creates a placard in any size the user wants.
- //
- ControlHandle
- CreatePlacard( WindowPtr window )
- {
- DialogPtr dialog;
- SInt16 itemHit = 0;
- ControlHandle control = nil;
- SInt16 type;
- Handle handle;
- Rect rect;
- Rect bounds = { 0, 0, 0, 0 };
- Str255 text;
- SInt32 number;
- ControlKeyFilterUPP filterProc;
- ControlHandle tempControl;
-
- dialog = GetNewDialog( 2008, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- filterProc = NewControlKeyFilterProc( NumericFilter );
-
- GetDialogItemAsControl( dialog, kPlacardHeightText, &tempControl );
- SetEditTextKeyFilter( tempControl, filterProc );
- GetDialogItemAsControl( dialog, kPlacardWidthText, &tempControl );
- SetEditTextKeyFilter( tempControl, filterProc );
-
- SetDialogDefaultItem( dialog, kPlacardOKButton );
- SetDialogCancelItem( dialog, kPlacardCancelButton );
-
- while ( itemHit != kPlacardCancelButton && itemHit != kPlacardOKButton )
- {
- ModalDialog( nil, &itemHit );
- }
- DisposeControlKeyFilterUPP( filterProc );
-
- if ( itemHit == kPlacardCancelButton )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- GetDialogItem( dialog, kPlacardHeightText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &number );
- bounds.bottom = number;
-
- GetDialogItem( dialog, kPlacardWidthText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &number );
- bounds.right = number;
-
- DisposeDialog( dialog );
-
- CreatePlacardControl( window, &bounds, &control );
- if ( control == nil ) return nil;
-
- SetControlVisibility( control, false, false );
-
- return control;
- }
-
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Ä CreatePopupArrow PUBLIC
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // This routine creates a popup arrow in any direction and size the user wants.
- //
- ControlHandle
- CreatePopupArrow( WindowPtr window )
- {
- enum { kEast = 1, kWest, kNorth, kSouth };
-
- DialogRef dialog;
- SInt16 itemHit = 0;
- Rect bounds = { 0, 0, 50, 50 };
- ControlPopupArrowOrientation orientation;
- ControlPopupArrowSize size;
- ControlRef control;
- ControlRef tempControl;
-
- dialog = GetNewDialog( 2009, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- SetDialogDefaultItem( dialog, kPopArrowOKButton );
- SetDialogCancelItem( dialog, kPopArrowCancelButton );
-
- while ( itemHit != kPopArrowCancelButton && itemHit != kPopArrowOKButton )
- {
- ModalDialog( nil, &itemHit );
-
- GetDialogItemAsControl( dialog, itemHit, &tempControl );
- switch ( itemHit )
- {
- case kPopArrowSmallCheck:
- SetControlValue( tempControl, !GetControlValue( tempControl ) );
- break;
- }
- }
-
- if ( itemHit == kPopArrowCancelButton )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- size = kControlPopupArrowSizeNormal;
- GetDialogItemAsControl( dialog, kPopArrowSmallCheck, &tempControl );
- if ( GetControlValue( tempControl ) == 1 )
- size = kControlPopupArrowSizeSmall;
-
- GetDialogItemAsControl( dialog, kPopArrowDirPopup, &tempControl );
- switch ( GetControlValue( tempControl ) )
- {
- default:
- case kEast: orientation = kControlPopupArrowOrientationEast; break;
- case kWest: orientation = kControlPopupArrowOrientationWest; break;
- case kNorth: orientation = kControlPopupArrowOrientationNorth; break;
- case kSouth: orientation = kControlPopupArrowOrientationSouth; break;
- }
-
- DisposeDialog( dialog );
-
- CreatePopupArrowControl( window, &bounds, orientation, size, &control );
-
- if ( control != nil )
- SetControlVisibility( control, false, false );
-
- return control;
- }
-
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Ä CreateScrollBar PUBLIC
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Creates a scroll bar.
- //
- ControlHandle
- CreateScrollBar( WindowPtr window )
- {
- DialogPtr dialog;
- SInt16 itemHit = 0;
- SInt16 type;
- Handle handle;
- Rect rect;
- SInt32 length;
- Str255 text;
- Rect bounds = { 0, 0, 16, 16 };
- ControlRef tempControl;
- ControlRef control;
-
- dialog = GetNewDialog( 2010, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- SetDialogDefaultItem( dialog, kScrollOKButton );
- SetDialogCancelItem( dialog, kScrollCancelButton );
-
- while ( itemHit != kScrollCancelButton && itemHit != kScrollOKButton )
- {
- ModalDialog( nil, &itemHit );
- }
-
- if ( itemHit == kScrollCancelButton )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- GetDialogItem( dialog, kScrollLengthText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &length );
-
- GetDialogItemAsControl( dialog, kScrollRadioGroup, &tempControl );
- if ( GetControlValue( tempControl ) == 1 )
- bounds.right = length;
- else
- bounds.bottom = length;
-
- DisposeDialog( dialog );
-
- CreateScrollBarControl( window, &bounds, 0, 0, 100, 0, false, nil, &control );
-
- if ( control != nil )
- SetControlVisibility( control, false, false );
-
- return control;
- }
-
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Ä CreateTabs PUBLIC
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Creates a standard push button.
- //
- ControlHandle
- CreateTabs( WindowPtr window )
- {
- enum { kEast = 1, kWest, kNorth, kSouth };
-
- DialogPtr dialog;
- SInt16 itemHit = 0;
- ControlRef control = nil;
- ControlRef handle;
- Str255 text;
- Rect bounds = { 0, 0, 100, 300 };
- ControlTabSize size;
- ControlTabDirection direction;
- Boolean useIcons;
- ControlKeyFilterUPP filterProc;
- short i;
- ControlTabInfoRec infoRec;
- SInt32 numTabs;
- unsigned char *titles[4] = {"\pA","\pBunch","\pOf","\pTitles."};
-
- dialog = GetNewDialog( 2018, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- SetDialogDefaultItem( dialog, kStdOkItemIndex );
- SetDialogCancelItem( dialog, kStdCancelItemIndex );
-
- filterProc = NewControlKeyFilterProc( NumericFilter );
-
- GetDialogItemAsControl( dialog, kTabNumberTabs, &control );
- SetEditTextKeyFilter( control, filterProc );
-
- while ( itemHit != kStdCancelItemIndex && itemHit != kStdOkItemIndex )
- {
- ModalDialog( nil, &itemHit );
-
- GetDialogItemAsControl( dialog, itemHit, &handle );
- if (itemHit == kTabUseIcon)
- SetControlValue( (ControlHandle)handle, !GetControlValue( (ControlHandle)handle ) );
- }
-
- if ( itemHit == kStdCancelItemIndex )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- GetDialogItemAsControl( dialog, kTabNumberTabs, &handle );
- GetDialogItemText( (Handle) handle, text );
- StringToNum( text, &numTabs );
-
- // determine which direction the user chose from the popup
- GetDialogItemAsControl( dialog, kTabDirectionPopup, &handle);
- switch (GetControlValue(handle))
- {
- case kEast: direction = kControlTabDirectionEast; break;
- case kWest: direction = kControlTabDirectionWest; break;
- default:
- case kNorth: direction = kControlTabDirectionNorth; break;
- case kSouth: direction = kControlTabDirectionSouth; break;
- }
-
- size = kControlTabSizeLarge;
- GetDialogItemAsControl( dialog, kTabSizeGroup, &handle);
- if (GetControlValue(handle) != 1)
- size = kControlTabSizeSmall;
-
- GetDialogItemAsControl( dialog, kTabUseIcon, &handle);
-
- useIcons = GetControlValue(handle);
-
- DisposeDialog( dialog );
-
- CreateTabsControl( window, &bounds, size, direction, numTabs, nil, &control );
- if ( control == nil ) return nil;
-
- SetControlVisibility( control, false, false );
-
- /** now set the tab names manually **/
-
- infoRec.version = kControlTabInfoVersionZero;
- infoRec.iconSuiteID = useIcons ? 128 : 0;
-
- for(i=1;i<=numTabs;i++)
- {
- // cycle through the sample titles
- // memcpy(&infoRec.name,titles[(i-1) % 4], *titles[(i-1) % 4]+1);
- BlockMove(titles[(i-1) % 4], &infoRec.name, *titles[(i-1) % 4]+1);
-
- SetControlData(control, i, kControlTabInfoTag, sizeof(ControlTabInfoRec), (Ptr) &infoRec);
- }
-
- return control;
- }
-
-
-
-
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Ä CreatePushButton PUBLIC
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Creates a standard push button.
- //
- ControlHandle
- CreatePushButton( WindowPtr window )
- {
- DialogPtr dialog;
- SInt16 itemHit = 0;
- ControlHandle control = nil;
- SInt16 type;
- Handle handle;
- Rect rect;
- Str255 text;
- Rect bounds = { 0, 0, 22, 22 };
- Boolean isDefault;
- SInt16 baseLine;
- ControlHandle tempControl;
-
- dialog = GetNewDialog( 2012, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- SetDialogDefaultItem( dialog, kPushButtonOKButton );
- SetDialogCancelItem( dialog, kPushButtonCancelButton );
-
- while ( itemHit != kPushButtonCancelButton && itemHit != kPushButtonOKButton )
- {
- ModalDialog( nil, &itemHit );
-
- GetDialogItem( dialog, itemHit, &type, &handle, &rect );
- switch ( itemHit )
- {
- case kPushButtonDefaultCheck:
- SetControlValue( (ControlHandle)handle, !GetControlValue( (ControlHandle)handle ) );
- break;
- }
- }
-
- if ( itemHit == kPushButtonCancelButton )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- GetDialogItem( dialog, kPushButtonTitleText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
-
- GetDialogItemAsControl( dialog, kPushButtonDefaultCheck, &tempControl );
- isDefault = (GetControlValue( tempControl ) == 1 );
-
- DisposeDialog( dialog );
-
- CreatePushButtonControl( window, &bounds, text, &control );
- if ( control == nil ) return nil;
-
- SetControlVisibility( control, false, false );
-
- if ( isDefault )
- {
- SetControlData( control, 0, kControlPushButtonDefaultTag, sizeof( isDefault ),
- (Ptr)&isDefault );
- }
-
- if ( GetBestControlRect( control, &bounds, &baseLine ) == noErr )
- SetControlBounds( control, &bounds );
-
- return control;
- }
-
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Ä CreateCheckBox PUBLIC
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Creates a standard check box.
- //
- ControlHandle
- CreateCheckBox( WindowPtr window )
- {
- return CreateCheckBoxOrRadioButton( window, true );
- }
-
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Ä CreateRadioButton PUBLIC
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Creates a standard radio button.
- //
- ControlHandle
- CreateRadioButton( WindowPtr window )
- {
- return CreateCheckBoxOrRadioButton( window, false );
- }
-
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Ä CreateCheckBoxOrRadioButton PRIVATE
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Creates a standard check box or radio button.
- //
- static ControlHandle
- CreateCheckBoxOrRadioButton( WindowPtr window, Boolean isCheckBox )
- {
- DialogRef dialog;
- SInt16 itemHit = 0;
- ControlRef control = nil;
- Handle handle;
- Str255 text;
- Rect bounds = { 0, 0, 22, 22 };
- SInt16 baseLine;
- Boolean doAutoToggle;
-
- dialog = GetNewDialog( 2013, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- GetDialogItemAsControl(dialog, kCheckBoxTitleText, (ControlHandle *) &handle);
-
- if ( isCheckBox )
- {
- SetWTitle( (WindowPtr) dialog, "\pCheck Box" );
- SetDialogItemText( handle, "\pCheck Box");
- }
- else
- {
- SetWTitle( (WindowPtr) dialog, "\pRadio Button" );
- SetDialogItemText( handle, "\pRadio Button");
- }
-
- SetDialogDefaultItem( dialog, kCheckBoxOKButton );
- SetDialogCancelItem( dialog, kCheckBoxCancelButton );
-
- ShowWindow( GetDialogWindow( dialog ) );
-
- while ( itemHit != kCheckBoxCancelButton && itemHit != kCheckBoxOKButton )
- {
- ModalDialog( nil, &itemHit );
-
- if (itemHit == 5)
- {
- GetDialogItemAsControl(dialog, 5, (ControlHandle *) &handle);
- SetControlValue((ControlHandle) handle, !GetControlValue((ControlHandle) handle));
- }
- }
-
- if ( itemHit == kCheckBoxCancelButton )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- GetDialogItemAsControl(dialog, kCheckBoxTitleText, (ControlHandle *) &handle);
- GetDialogItemText( handle, text );
-
- GetDialogItemAsControl(dialog, 5, (ControlHandle *) &handle);
- doAutoToggle = GetControlValue((ControlHandle) handle) == 1;
-
- DisposeDialog( dialog );
-
- if ( isCheckBox )
- CreateCheckBoxControl( window, &bounds, text, doAutoToggle, &control );
- else
- CreateRadioButtonControl( window, &bounds, text, doAutoToggle, &control );
-
- if ( control == nil ) return nil;
-
- SetControlVisibility( control, false, false );
-
- if ( GetBestControlRect( control, &bounds, &baseLine ) == noErr )
- SetControlBounds( control, &bounds );
-
- return control;
- }
-
-
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Ä CreateImageWell PUBLIC
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // This routine creates an image well.
- //
- ControlHandle
- CreateImageWell( WindowPtr window )
- {
- DialogRef dialog;
- SInt16 itemHit = 0;
- SInt16 type;
- Handle handle;
- Rect rect;
- Rect bounds = { 0, 0, 0, 0 };
- Str255 text;
- SInt32 number;
- SInt32 resID = 0;
- ControlKeyFilterUPP filterProc;
- ControlRef tempControl;
- ControlButtonContentInfo content;
- ControlRef control;
-
- dialog = GetNewDialog( 2011, nil, (WindowPtr)-1L );
- if ( dialog == nil ) return nil;
-
- filterProc = NewControlKeyFilterProc( NumericFilter );
-
- GetDialogItemAsControl( dialog, kImageHeightText, &tempControl );
- SetEditTextKeyFilter( tempControl, filterProc );
-
- GetDialogItemAsControl( dialog, kImageWidthText, &tempControl );
- SetEditTextKeyFilter( tempControl, filterProc );
-
- GetDialogItemAsControl( dialog, kImageResIDText, &tempControl );
- SetEditTextKeyFilter( tempControl, filterProc );
-
- SetDialogDefaultItem( dialog, kImageOKButton );
- SetDialogCancelItem( dialog, kImageCancelButton );
-
- while ( itemHit != kImageCancelButton && itemHit != kImageOKButton )
- {
- ModalDialog( nil, &itemHit );
- }
- DisposeControlKeyFilterUPP( filterProc );
-
- if ( itemHit == kImageCancelButton )
- {
- DisposeDialog( dialog );
- return nil;
- }
-
- GetDialogItem( dialog, kImageHeightText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &number );
- bounds.bottom = number;
-
- GetDialogItem( dialog, kImageWidthText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &number );
- bounds.right = number;
-
- GetDialogItem( dialog, kImageResIDText, &type, &handle, &rect );
- GetDialogItemText( handle, text );
- StringToNum( text, &resID );
- content.u.resID = resID;
-
- GetDialogItemAsControl( dialog, kImageContentPopup, &tempControl );
- switch ( GetControlValue( tempControl ) )
- {
- case 1: content.contentType = kControlContentIconSuiteRes; break;
- case 2: content.contentType = kControlContentCIconRes; break;
- case 3: content.contentType = kControlContentPictRes; break;
- default: content.contentType = kControlNoContent; break;
- }
-
- DisposeDialog( dialog );
-
- CreateImageWellControl( window, &bounds, &content, &control );
-
- if ( control != nil )
- SetControlVisibility( control, false, false );
-
- return control;
- }
-
- ControlHandle
- CreateList(WindowPtr window)
- {
- ControlRef myListControl;
- Rect bounds = { 50, 50, 200, 200 };
- AlertStdAlertParamRec myAlertParam = {true, false, nil, "\pListBox", "\pListBoxAutoSize",nil, 1, 0, kWindowDefaultPosition};
- SInt16 outItemHit;
- Boolean autoSize;
- ListDefSpec listDef;
-
- StandardAlert(kAlertPlainAlert, "\pWould you like it to use kControlListBoxProc or kControlListBoxAutoSizeProc?",nil,
- &myAlertParam, &outItemHit);
-
- autoSize = outItemHit == 2;
-
- listDef.defType = kListDefStandardTextType;
-
- CreateListBoxControl( window, &bounds, autoSize, 30, 30, true, true, 50, 16, true,
- &listDef, &myListControl );
-
- if (myListControl)
- {
- ListHandle theList;
- Size actualSize;
- OSErr theError;
-
- SetControlVisibility( myListControl, false, false );
-
- theError = GetControlData(myListControl, kControlNoPart, kControlListBoxListHandleTag, 4, (Ptr) &theList, &actualSize);
-
- if (theError == noErr)
- {
- short i,j;
- Str255 theString;
- long theNum=1;
- Cell whichCell;
-
- for(i=0; i<30; i++)
- for(j=0; j<30; j++)
- {
- NumToString(theNum, theString);
- theNum++;
- whichCell.h = i;
- whichCell.v = j;
- LSetCell(&theString[1], theString[0],whichCell, theList);
- }
- }
- }
- return (myListControl);
- }
-
-
-
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Ä GetIconSize UTILITY
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // This routine attempts to get the height and width of the icon specified by resID.
- // It assumes that ICONs are always 32x32. For cicns, we go into the resource and look
- // at the pixmap's bounding rectangle.
- //
- static void
- GetPictureSize( SInt16 resID, SInt32* height, SInt32* width )
- {
- PicHandle picture;
-
- *height = 0;
- *width = 0;
-
- picture = GetPicture( resID );
- if ( picture == nil ) return;
-
- *height = (**picture).picFrame.bottom - (**picture).picFrame.top;
- *width = (**picture).picFrame.right - (**picture).picFrame.left;
- }
-
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Ä GetIconSize UTILITY
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // This routine attempts to get the height and width of the icon specified by resID.
- // It assumes that ICONs are always 32x32. For cicns, we go into the resource and look
- // at the pixmap's bounding rectangle.
- //
- static void
- GetIconSize( SInt16 resID, SInt32* height, SInt32* width )
- {
- Handle icon;
-
- *height = 0;
- *width = 0;
-
- icon = GetResource( 'ICON', resID );
- if ( icon == nil )
- {
- icon = GetResource( 'cicn', resID );
- if ( icon == nil ) return;
-
- *height = (**(CIconHandle)icon).iconPMap.bounds.bottom - (**(CIconHandle)icon).iconPMap.bounds.top;
- *width = (**(CIconHandle)icon).iconPMap.bounds.right - (**(CIconHandle)icon).iconPMap.bounds.left;
- }
- else
- {
- *height = *width = 32;
- }
- }
-
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // Ä NumericFilter PUBLIC
- //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
- // This function is a key filter for edit text fields. It ensures that all input is
- // numeric. It also allows editing keys to pass thru so that the edit text actually
- // remains editable!
- //
- pascal ControlKeyFilterResult
- NumericFilter( ControlHandle control, SInt16* keyCode, SInt16* charCode, EventModifiers* modifiers )
- {
- #pragma unused( control, keyCode, modifiers )
-
- if ( ((char)*charCode >= '0') && ((char)*charCode <= '9') )
- return kControlKeyFilterPassKey;
-
- switch ( *charCode )
- {
- case '-':
- case kLeftArrow:
- case kRightArrow:
- case kUpArrow:
- case kDownArrow:
- case kBackspace:
- return kControlKeyFilterPassKey;
-
- default:
- return kControlKeyFilterBlockKey;
- }
- }
-